<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Declaring and organizing tests</title>
<link rel="stylesheet" href="../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Boost.Test">
<link rel="up" href="../index.html" title="Boost.Test">
<link rel="prev" href="usage_variants.html" title="Usage variants">
<link rel="next" href="tests_organization/test_cases.html" title="Test cases">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="usage_variants.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tests_organization/test_cases.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_test.tests_organization"></a><a class="link" href="tests_organization.html" title="Declaring and organizing tests">Declaring and organizing
    tests</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="tests_organization/test_cases.html">Test cases</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="tests_organization/test_cases/test_organization_nullary.html">Test
        cases without parameters</a></span></dt>
<dt><span class="section"><a href="tests_organization/test_cases/test_case_generation.html">Data-driven
        test cases</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="tests_organization/test_cases/test_case_generation/datasets.html">Datasets</a></span></dt>
<dt><span class="section"><a href="tests_organization/test_cases/test_case_generation/datasets_auto_registration.html">Declaring
          and registering test cases with datasets</a></span></dt>
<dt><span class="section"><a href="tests_organization/test_cases/test_case_generation/operations.html">Operations
          on dataset</a></span></dt>
<dt><span class="section"><a href="tests_organization/test_cases/test_case_generation/generators.html">Datasets
          generators</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="tests_organization/test_cases/test_organization_templates.html">Template
        test cases</a></span></dt>
<dt><span class="section"><a href="tests_organization/test_cases/param_test.html">Parametrized
        test cases</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="tests_organization/test_tree.html">Test tree</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="tests_organization/test_tree/test_suite.html">Test
        suite</a></span></dt>
<dt><span class="section"><a href="tests_organization/test_tree/master_test_suite.html">Master
        test suite</a></span></dt>
<dt><span class="section"><a href="tests_organization/test_tree/test_naming.html">Tests
        naming</a></span></dt>
<dt><span class="section"><a href="tests_organization/test_tree/test_tree_content.html">Test
        tree content</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="tests_organization/decorators.html">Decorators</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="tests_organization/decorators/suite_level_decorators.html">Suite-level
        decorators</a></span></dt>
<dt><span class="section"><a href="tests_organization/decorators/explicit_decorator_declaration.html">Explicit
        decorator declaration</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="tests_organization/fixtures.html">Fixtures</a></span></dt>
<dd><dl>
<dt><span class="section"><a href="tests_organization/fixtures/models.html">Fixture
        models</a></span></dt>
<dt><span class="section"><a href="tests_organization/fixtures/case.html">Test case
        fixture</a></span></dt>
<dt><span class="section"><a href="tests_organization/fixtures/per_test_suite_fixture.html">Test
        suite entry/exit fixture</a></span></dt>
<dt><span class="section"><a href="tests_organization/fixtures/global.html">Global
        fixture</a></span></dt>
</dl></dd>
<dt><span class="section"><a href="tests_organization/tests_dependencies.html">Managing
      test dependencies</a></span></dt>
<dt><span class="section"><a href="tests_organization/tests_grouping.html">Grouping
      tests into logical units by labels</a></span></dt>
<dt><span class="section"><a href="tests_organization/enabling.html">Enabling or disabling
      test unit execution</a></span></dt>
<dt><span class="section"><a href="tests_organization/semantic.html">Adding semantic
      to a test</a></span></dt>
<dt><span class="section"><a href="tests_organization/summary_of_the_api_for_declaring.html">Summary
      of the API for declaring and organizing tests</a></span></dt>
</dl></div>
<p>
      If you look at many legacy test modules, big chance is that it's implemented
      as one big test function that consists of a mixture of check and output statements.
      Is there anything wrong with it? Yes. There are various disadvantages in single
      test function approach:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
          One big function tends to become really difficult to manage if the number
          of checks exceeds a reasonable limit (true for any large function). What
          is tested and where - who knows?
        </li>
<li class="listitem">
          Many checks require similar preparations. This results in code repetitions
          within the test function.
        </li>
<li class="listitem">
          If a fatal error or an exception is caused by any checks within the test
          function the rest of tests are skipped and there is no way to prevent this.
        </li>
<li class="listitem">
          No way to perform only checks for a particular subsystem of the tested
          unit.
        </li>
<li class="listitem">
          No summary of how different subsystems of the tested unit performed under
          in the test.
        </li>
</ul></div>
<p>
      The above points should make it clear that it's preferable to split a <a class="link" href="section_glossary.html#ref_test_module">test module</a> into smaller <span class="bold"><strong>units</strong></span>.
      These units are the <span class="bold"><strong>test cases</strong></span>, the <span class="bold"><strong>test suites</strong></span> and the <span class="bold"><strong>fixtures</strong></span>.
    </p>
<div class="variablelist">
<p class="title"><b>Subjects covered by this section</b></p>
<dl class="variablelist">
<dt><span class="term">Declaration</span></dt>
<dd><p>
            The <span class="emphasis"><em>Unit Test Framework</em></span> supports several methods
            for declaring a <a class="link" href="tests_organization/test_cases.html" title="Test cases">test
            case</a>. Test cases can be implemented using free function like syntax
            or based on actual free function, function object, that can be defined
            with or without parameters/data, or as template functions to be run against
            various types.
          </p></dd>
<dt><span class="term">Organization</span></dt>
<dd><p>
            The <span class="emphasis"><em>Unit Test Framework</em></span> provides facilities to group
            several test cases into <a class="link" href="tests_organization/test_tree/test_suite.html" title="Test suite">test
            suites</a>. The test suites can be nested, and the set of test suites
            and test cases defines the <a class="link" href="tests_organization/test_tree.html" title="Test tree">test
            tree</a>, where the leaves are the test cases. Besides hierarchical
            structure the <span class="emphasis"><em>Unit Test Framework</em></span> allows you to
            organize the test tree using <a class="link" href="tests_organization/tests_grouping.html" title="Grouping tests into logical units by labels">logical
            grouping</a> and <a class="link" href="tests_organization/tests_dependencies.html" title="Managing test dependencies">dependencies</a>
            and provides you with controls to utilize the defined test tree organization
            the way you want (eg. from command line).
          </p></dd>
<dt><span class="term">Attributes</span></dt>
<dd><p>
            It is possible to specify test unit <span class="emphasis"><em>attributes</em></span> by
            using <a class="link" href="tests_organization/decorators.html" title="Decorators">decorators</a>.
            Attributes are used for a fine grained control over various aspects of
            test module execution, such as <span class="emphasis"><em>logical grouping</em></span>,
            <span class="emphasis"><em>dependencies</em></span>, <span class="emphasis"><em>expected failures</em></span>,
            etc.
          </p></dd>
<dt><span class="term">Setup/teardown test unit actions</span></dt>
<dd><p>
            When several tests shares the same set-up (environment, test data preparation,
            etc.), the preparation and cleanup code may be factorized in <a class="link" href="tests_organization/fixtures.html" title="Fixtures">fixtures</a>.
            In the <span class="emphasis"><em>Unit Test Framework</em></span>, fixtures can be associated
            to test cases, test suites or globally to the test module.
          </p></dd>
</dl>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2022 Boost.Test contributors<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="usage_variants.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tests_organization/test_cases.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
